/*
 * NodeSequence.hpp
 *
 *  Created on: 2009-11-13
 *      Author: ws
 */

#ifndef NODESEQUENCE_HPP_
#define NODESEQUENCE_HPP_


class Node;
class NodeSequence{
	struct _intrusive_node{
		Node* prev;
		Node* next;
	};
	Node *header;
	int _size;
public:
	class iterator{
		friend class NodeSequence;
		Node* ptr;
	public:
		iterator(Node* ptr): ptr(ptr)
		{

		}

		bool operator == (iterator  x)
		{
			if (x.ptr == ptr)
				return true;
			else
				return false;
		}

		bool operator != (iterator  x)
		{
			return ! ((*this) == x);
		}

		iterator  operator ++ (int );
		iterator&  operator ++ ();
		iterator  operator -- (int );
		iterator&  operator -- ();

		iterator operator + (int count);
		iterator operator - (int count);

		Node * operator ->()
		{
			return ptr;
		}

		Node&  operator *()
		{
			return (*ptr);
		}
		Node* ref(){return ptr;}
	};

	NodeSequence();
	~NodeSequence();

	int size(){ return _size; }
	void push_back(Node * n);
	void push_front(Node * n);

	iterator insert(iterator &pos, Node* n);

	Node * remove(iterator& pos);

	iterator begin()const;
	iterator end()const;
};
typedef NodeSequence::iterator NIter;

#endif /* NODESEQUENCE_HPP_ */
